package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.googlecode.gwtbb.client.only.widget.form.GetBooleanValue;
import com.googlecode.gwtbb.client.shared.validation.FieldId;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: May 5, 2009
 */
public class HtmledCheckBoxFormEntry extends HtmledFormEntry implements GetBooleanValue {
	private CheckBox entryCheckBox;
	private boolean defaultBooleanValue;

	public HtmledCheckBoxFormEntry(FieldId fieldId, boolean defaultBooleanValue, int row, int col, String htmlText, CheckBox entryCheckBox) {
		// we don't use defaultValue field, we use defaultBooleanValue
		super(fieldId, null, row, col, htmlText);
		this.entryCheckBox = entryCheckBox;
		this.defaultBooleanValue = defaultBooleanValue;
		clearValue();
	}

	public boolean getDefaultBooleanValue() {
		return defaultBooleanValue;
	}

	public void setDefaultBooleanValue(boolean defaultBooleanValue) {
		this.defaultBooleanValue = defaultBooleanValue;
	}

	public CheckBox getEntryCheckBox() {
		return entryCheckBox;
	}

	public void clearValue() {
		entryCheckBox.setChecked(defaultBooleanValue);
	}

	public boolean getBooleanValue() {
		return entryCheckBox.isChecked();
	}

	public String getDefaultValue() {
		return String.valueOf(getDefaultBooleanValue());
	}

	public Widget getEntryWidget() {
		return entryCheckBox;
	}

	public String getValue() {
		return String.valueOf(getBooleanValue());
	}

	public void setBooleanValue(boolean booleanValue) {
		entryCheckBox.setChecked(booleanValue);
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultBooleanValue = Boolean.valueOf(defaultValue);
	}

	public void setValue(String value) {
		entryCheckBox.setChecked(Boolean.valueOf(value));
	}
}
